/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_LABELTTF_IMPL__
#define __CC_PYTHON_IMPORT_O_LABELTTF_IMPL__

#include "python_object_labelttf.h"
#include "python_object_texture2d.h"

NS_CCPY_BEGIN
	CCSPRITE_OBJECT_WRAPPER_IMPL(CCLabelTTF, CPyLabelTTF)	

	PYCLASS_INIT_AND_BASE_2(CPyLabelTTF, CPySprite, CPyLabelProtocol, "CCLabelTTF", "Python CCLabelTTF Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyLabelTTF)
	PYCLASS_ADD_METHOD_EX(CPyLabelTTF, initWithString, METH_KEYWORDS|METH_VARARGS)
	PYCLASS_END_METHOD_DEF(CPyLabelTTF)
	PYCLASS_BEGIN_GETSET_DEF(CPyLabelTTF)
		PYCLASS_ADD_GETSET(CPyLabelTTF, HorizontalAlignment)
		PYCLASS_ADD_GETSET(CPyLabelTTF, VerticalAlignment)
		PYCLASS_ADD_GETSET(CPyLabelTTF, Dimensions)
		PYCLASS_ADD_GETSET(CPyLabelTTF, FontSize)
		PYCLASS_ADD_GETSET(CPyLabelTTF, FontName)
	PYCLASS_END_GETSET_DEF(CPyLabelTTF)
	PYCLASS_IMP_INTERFACE_NOINIT(CPyLabelTTF)
	
	int CPyLabelTTF::__init__(CPyLabelTTF *pySelf, PyObject *args, PyObject *kwds)
	{
		if( !args )
			return 0;
		static char* kwlist[] = {"string", "fontName", "fontSize", "dimensions", "hAlignment", "vAlignment", NULL};
		char *string = "";
		char *fontName = "";
		float fontSize = 0;
		PyObject *py_dimensions = NULL;
		int ha = -1;
		int va = -1;
		if (!PyArg_ParseTupleAndKeywords(args,kwds,"ssf|OII", kwlist, &string, &fontName, &fontSize, &py_dimensions, &ha, &va))
			return 0;
		cocos2d::CCLabelTTF *spr = dynamic_cast<cocos2d::CCLabelTTF *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		CPySize *dimensions = NULL;
		if(py_dimensions && PyObject_TypeCheck(py_dimensions, CPyClassBase::GetTypeObject<CPySize>()))
			dimensions = (CPySize *)py_dimensions;
		if(dimensions && ha >= 0)
		{
			if(va >= 0)
			{
				spr->initWithString(string, fontName, fontSize, dimensions->getCCObject(), (cocos2d::CCTextAlignment)ha, (cocos2d::CCVerticalTextAlignment)va);
			}else
			{
				spr->initWithString(string, fontName, fontSize, dimensions->getCCObject(), (cocos2d::CCTextAlignment)ha);
			}
		}else
		{
			spr->initWithString(string, fontName, fontSize);
		}
		return 0;
	}
	
	PYCLASS_METHOD_KW_IMPL(CPyLabelTTF, initWithString)
	{
		if( !pyArgs )
			return 0;
		static char* kwlist[] = {"string", "fontName", "fontSize", "dimensions", "hAlignment", "vAlignment", NULL};
		char *string = "";
		char *fontName = "";
		float fontSize = 0;
		PyObject *py_dimensions = NULL;
		int ha = -1;
		int va = -1;
		if (!PyArg_ParseTupleAndKeywords(pyArgs, pyKW, "ssf|OII", kwlist, &string, &fontName, &fontSize, &py_dimensions, &ha, &va))
			return 0;
		cocos2d::CCLabelTTF *spr = dynamic_cast<cocos2d::CCLabelTTF *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		CPySize *dimensions = NULL;
		if(PyObject_TypeCheck(py_dimensions, CPyClassBase::GetTypeObject<CPySize>()))
			dimensions = (CPySize *)py_dimensions;
		if(dimensions && ha >= 0)
		{
			if(va >= 0)
			{
				spr->initWithString(string, fontName, fontSize, dimensions->getCCObject(), (cocos2d::CCTextAlignment)ha, (cocos2d::CCVerticalTextAlignment)va);
			}else
			{
				spr->initWithString(string, fontName, fontSize, dimensions->getCCObject(), (cocos2d::CCTextAlignment)ha);
			}
		}else
		{
			spr->initWithString(string, fontName, fontSize);
		}
		return 0;
	}

	
	PYCLASS_GET_IMPL(CPyLabelTTF, HorizontalAlignment)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCLabelTTF *, CPyLabelTTF, getHorizontalAlignment, cocos2d::CCTextAlignment);
		return Py_BuildValue("I", static_cast<int>(v));
	}

	PYCLASS_SET_IMPL(CPyLabelTTF, HorizontalAlignment)
	{
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCLabelTTF *, CPyLabelTTF, setHorizontalAlignment, (cocos2d::CCTextAlignment)PyLong_AsUnsignedLong(pyValue));
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPyLabelTTF, VerticalAlignment)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCLabelTTF *, CPyLabelTTF, getVerticalAlignment, cocos2d::CCVerticalTextAlignment);
		return Py_BuildValue("I", static_cast<int>(v));
	}

	PYCLASS_SET_IMPL(CPyLabelTTF, VerticalAlignment)
	{
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCLabelTTF *, CPyLabelTTF, setVerticalAlignment, (cocos2d::CCVerticalTextAlignment)PyLong_AsUnsignedLong(pyValue));
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPyLabelTTF, Dimensions)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCLabelTTF *, CPyLabelTTF, getDimensions, cocos2d::CCSize);
		CPySize *si = CPySize::create(v);
		return (PyObject *)si;
	}

	PYCLASS_SET_IMPL(CPyLabelTTF, Dimensions)
	{
		if(!PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPySize>()))
			return 0;
		CPySize *pt = (CPySize *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCLabelTTF *, CPyLabelTTF, setDimensions, pt->getCCObject());
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPyLabelTTF, FontSize)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCLabelTTF *, CPyLabelTTF, getFontSize, float);
		return Py_BuildValue("f", v);
	}

	PYCLASS_SET_IMPL(CPyLabelTTF, FontSize)
	{
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCLabelTTF *, CPyLabelTTF, setFontSize, PyFloat_AsDouble(pyValue));
		return 0;
	}
	PYCLASS_GET_IMPL(CPyLabelTTF, FontName)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCLabelTTF *, CPyLabelTTF, getFontName, const char* );
		return Py_BuildValue("s", v);
	}

	PYCLASS_SET_IMPL(CPyLabelTTF, FontName)
	{
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCLabelTTF *, CPyLabelTTF, setFontName, PyString_AsString(pyValue));
		return 0;
	}
NS_CCPY_END

#endif